package com.mlong.admin.modular.unicomjs.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kordar.admin.kernel.wrapper.QueryWrapperEntity;
import com.kordar.datalist.DatalistService;
import com.kordar.datalist.ExcelDatalistService;
import com.kordar.datalist.ResultEntity;
import com.mlong.admin.modular.unicomjs.entity.Order;
import com.mlong.admin.modular.unicomjs.service.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@AllArgsConstructor
@Controller
@RequestMapping("unicomjs")
public class OrderController {

    private final OrderService orderService;
    private final DatalistService datalistService;
    private final ExcelDatalistService excelDatalistService;

    @GetMapping("order/index")
    public String index() {
        return "pages/modular/unicomjs/order/index";
    }

    @RequestMapping("order/list")
    @ResponseBody
    public ResultEntity<Object> menuList(@RequestBody QueryWrapperEntity<Order> entity) {
        IPage<Order> iPage = orderService.iPage(entity);
        return new ResultEntity<>(datalistService.render(iPage.getRecords(), Order.class), iPage.getTotal());
    }

    @RequestMapping("order/excel-list")
    @ResponseBody
    public ResultEntity<Object> excel(@RequestBody QueryWrapperEntity<Order> entity) {
        IPage<Order> iPage = orderService.excelData(entity, 10000);
        return new ResultEntity<>(excelDatalistService.render(iPage.getRecords(), Order.class));
    }

}
